/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */

package com.nai365.nart.member.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nai365.nart.common.core.util.R;
import com.nai365.nart.common.excel.annotation.ResponseExcel;
import com.nai365.nart.common.log.annotation.SysLog;
import com.nai365.nart.common.security.annotation.Inner;
import com.nai365.nart.member.entity.RealName;
import com.nai365.nart.member.service.RealNameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 实名
 *
 * @author baogs
 * @date 2022-07-01 10:52:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/realname" )
@Api(value = "realname", tags = "实名管理")
public class RealNameController {

    private final  RealNameService realNameService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param realName 实名
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getRealNamePage(Page page, RealName realName) {
        return R.ok(realNameService.page(page, Wrappers.query(realName)));
    }


    /**
     * 通过id查询实名
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(realNameService.getById(id));
    }

    /**
     * 新增实名
     * @param realName 实名
     * @return R
     */
    @ApiOperation(value = "新增实名", notes = "新增实名")
    @SysLog("新增实名" )
    @PostMapping
	@Inner
    public R save(@RequestBody RealName realName) {
        return R.ok(realNameService.save(realName));
    }

    /**
     * 修改实名
     * @param realName 实名
     * @return R
     */
    @ApiOperation(value = "修改实名", notes = "修改实名")
    @SysLog("修改实名" )
    @PutMapping
    public R updateById(@RequestBody RealName realName) {
        return R.ok(realNameService.updateById(realName));
    }

    /**
     * 通过id删除实名
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除实名", notes = "通过id删除实名")
    @SysLog("通过id删除实名" )
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(realNameService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param realName 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<RealName> export(RealName realName) {
        return realNameService.list(Wrappers.query(realName));
    }

	/**
	 * 根据手机号查询RealName对象
	 * @param phone
	 * @return
	 */
	@GetMapping("/find/{phone}" )
	@Inner
	public RealName findRealNameByPhone(@PathVariable("phone" ) String phone){
		RealName realName=realNameService.findRealNameByPhone(phone);
    	return realName;
	}


}
